package com.yudean.esb.util;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author : DL<duanlei@gdyd.com>
 * @version : 1.0
 */
public class IDGenerator {
    private static AtomicInteger counter;

    static {
        Random random = new Random();
        int seed = random.nextInt(1000);
        counter = new AtomicInteger(seed);
    }

    /**
     * 长生消息id
     */
    public static long getAtomicCounter() {
        if (counter.get() > 999999) {
            counter.set(1);
        }
        long time = System.currentTimeMillis();
        return time * 1000 + counter.incrementAndGet();
    }

    private static long incrementAndGet() {
        return counter.incrementAndGet();
    }

    public static String getHex() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

//    public static void  main(String[] args){
//        System.out.println(getHex());
//    }

}
